﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace MyVocationSpace
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;

            if (Session["UserID"] != null)
            {
                btnSubmit.Visible = false;
            }
            else
            {
                btnSubmit.Visible = true;
            }

            if (!IsPostBack)
            {
                //BAL.Industry.PopulateIndustry(ref ddlIndustry);
                BAL.Industry.PopulateCountry(ref ddlCountry);
              
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string first_name = txtFname.Text;
                string lastName = txtLname.Text;
                int Idcountry = Convert.ToInt32(ddlCountry.SelectedValue);
                //int IdIndustry = Convert.ToInt32(ddlIndustry.SelectedValue);
                string emailId = txtEmail.Text;
                string pass = txtPass.Text;
                string encrypted_pass = BAL.Encryption.Encript(pass, "&%#@?,:*");
                string strVal = BAL.Users.VerifyUserID(emailId, "");
                if (strVal == "-1")
                {
                    int UserID = BAL.Users.UserRegistration(first_name, lastName, emailId, encrypted_pass, Idcountry);
                    BAL.Users.InsertExperienceDetails(UserID);
                    BAL.Users.SendUserDetails(first_name, emailId, pass);
                    BAL.Users.RegLink(emailId, UserID.ToString(), encrypted_pass, first_name);
                    idSpanMsg.Visible = true; 
                    idSpanMsg.InnerHtml = "<span class=\"doneImg\"></span>Thank You for registering with us.";
                    clear();
                }
                else
                {
                    idSpanMsg.Visible = true;
                    idSpanMsg.InnerHtml = "Email ID already registered.";
                }

               // btnSubmit.Visible = false;
            }
        }
        public void clear()
        {
            txtFname.Text = "";
            txtLname.Text = "";
            ddlCountry.SelectedIndex = 0;
            //ddlIndustry.SelectedIndex = 0;
            txtEmail.Text = "";
            txtPass.Text = "";

        }

        protected void btnGo_Click(object sender, EventArgs e)
        {
            string strIndustry = txtIndustry.Text;
            string strVocation = txtVocation.Text;
            if (strIndustry == "Enter industry name")
            { 
                strIndustry = "";
                
            }
            if ((strIndustry != "Enter industry name") && (strIndustry != ""))
            {
                Response.Redirect("SearchMemberList.aspx?Industry=" + strIndustry);
            }

            if (strVocation == "Enter vocation")
            { 
                strVocation = "";
               
            }
            if (strVocation != "Enter vocation" || strVocation != "")
            {
                Response.Redirect("SearchMemberList.aspx?Vocation=" + strVocation);
            }
            //Response.Redirect("SearchMemberList.aspx?Industry="+strIndustry+"&Vocation="+strVocation+"");
        }
       

    }
}